package com.briup.jz.web.controller;

import com.briup.jz.bean.Article;

import com.briup.jz.bean.extend.ArticleExtend;
import com.briup.jz.dao.extend.ArticleExtendMapper;
import com.briup.jz.service.IArticleService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(description="学生风采相关接口")
@Validated
@RestController  //返回值都为 json对象
@RequestMapping("/article")
public class ArticleController {
    //依赖注入
    @Resource
    private IArticleService iArticleService;


    //实现插入操作
    @ApiOperation(value = "插入学生风采")
    @GetMapping("/save")
    public Message save(Article article){

        iArticleService.save(article);
        return MessageUtil.success("插入成功");
    }



    //实现查询操作
    @ApiOperation(value = "通过id展示学生风采")
    @GetMapping("/show")
    public Message show(String title){

        List<Article> list=iArticleService.query(title);
        return MessageUtil.success(list);
    }



//    实现多对一级联查询

    @ApiOperation(value = "多对一级联查询展示学生风采")
    @GetMapping("/jilian")
    public Message jilian(String title, String status, Long categoryId){
        List<ArticleExtend> list=iArticleService.queryCatogory(title,status,categoryId);

        return MessageUtil.success(list);
    }



    //实现一对多级联查询
    @ApiOperation(value = "一对多级联展示学生风采")
    @GetMapping("/ontToManyJiLian")
    public Message oneToMany(Long id){
        ArticleExtend articleExtend=iArticleService.read(id);
        return MessageUtil.success(articleExtend);
    }


}
